#include "gameoverdialog.h"
#include <QPalette>

GameOverDialog::GameOverDialog(int score,int highScore, QWidget *parent) : QDialog(parent), score(score)
{
    setWindowTitle("游戏结束");
    setFixedSize(300, 200);
    //确保对话框不会被父窗口销毁影响
        setAttribute(Qt::WA_DeleteOnClose);
    setModal(true);

    // 设置背景色
    QPalette palette;
    palette.setColor(QPalette::Window, QColor(70, 70, 70));
    setPalette(palette);

    // 创建布局
    QVBoxLayout *layout = new QVBoxLayout(this);

    // 添加得分标签
    m_titleLabel = new QLabel(QString("此次得分: %1").arg(score), this);

    QFont font = m_titleLabel->font();
    font.setPointSize(24);
    font.setBold(true);
    m_titleLabel->setFont(font);
    m_titleLabel->setStyleSheet("color: white;");
    layout->addWidget(m_titleLabel);

    // 添加"再来一次"按钮
    m_restartBtn = new QPushButton("再来一次", this);
    m_restartBtn->setStyleSheet(
        "QPushButton {"
        "background-color: #4CAF50;"
        "color: white;"
        "border: none;"
        "padding: 8px;"
        "font-size: 14px;"
        "}"
        "QPushButton:hover {"
        "background-color: #45a049;"
        "}"
    );
    layout->addWidget(m_restartBtn);

    // 添加"回到菜单"按钮
    m_menuBtn = new QPushButton("回到菜单", this);
    m_menuBtn->setStyleSheet(
        "QPushButton {"
        "background-color: #f44336;"
        "color: white;"
        "border: none;"
        "padding: 8px;"
        "font-size: 14px;"
        "}"
        "QPushButton:hover {"
        "background-color: #d32f2f;"
        "}"
    );
    layout->addWidget(m_menuBtn);

    // 修改按钮信号连接部分
    connect(m_restartBtn, &QPushButton::clicked, this, [this]() {
        emit restartGame();
        close();
    });

    connect(m_menuBtn, &QPushButton::clicked, this, [this]() {
        emit returnToMenu();
        close();
    });
}

void GameOverDialog::onDialogClosed()
{
    // 可以保留这个函数，但不再需要disconnect
    // 因为对话框关闭时会自动清理
}
